package com.yjt.termworks;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.yjt.termworks.sql.MyHelper;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        toPush();
        //
//        saveStorageSQL();
        //
        TextView tv_welcome = findViewById(R.id.tv_welcome);
        tv_welcome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("------------->","tvwelcom");
                Intent intent = new Intent();
                intent.setClass(WelcomeActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });
    }
    private void toPush(){
         Timer timer;
         TimerTask task;

        timer = new Timer();
        task = new TimerTask() {

            @Override
            public void run() {
                Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
                // 取消定时任务
                timer.cancel();

                startActivity(intent);
                finish(); // 销毁当前页面，防止跳转后返回到欢迎页面
            }
        };


        // 将定时任务放到 timer 上执行
        timer.schedule(task, 3000);
    }

    private void saveStorageSQL(){
        MyHelper myHelper = new MyHelper(WelcomeActivity.this);    // 数据库
        SQLiteDatabase db = myHelper.getWritableDatabase();
        ContentValues values = null;
        String[] nameList = {"班主任老师","王同学","数学老师","周同学家长","乔同学家长","杨同学家长"};
        String[] avatarList = {"20230620081014000000563.jpg","20230619092129000000629.jpg","20230615080557000000260.jpg","20230619091547000000074.jpg","20230622073701000000960.jpg","20230619092443000000048.jpg"};
        String[] circleImages ={"20230620100659000000349.jpg,20230620103507000000634.jpg","20230620100659000000349.jpg,20230620100659000000349.jpg","20230620100659000000349.jpg,20230615080557000000260.jpg","20230620100659000000349.jpg,20230620100659000000349.jpg","20230620103507000000634.jpg,20230620103545000000969.jpg","20230620100659000000349.jpg,20230620103507000000634.jpg"};
        String[] messList = {"周末竟然还要上班，救命！","还不去学习，加油！","好好学习，天天向上!，加油！","杨同学又是倒数第一名，快去搬砖！","周同学又拿到了班级第一名，加油！","乔同学怎么又在睡觉，快起来学习！"};
        Integer[] likeNumList = {13,21,23,12,2,43};
        String[] commentList = {"","我来评论了","","","我来评论了",""};
        // user
        String[] phoneList = {"13653864793","13245937358","15378923486","15434786543","15267303402","123"};
        String[] passwordList = {"admin","admin","admin","admin","admin","admin"};
        String[] cover = {"20230623065452000000316.jpg","20230623065500000000967.jpg","20230620103545000000969.jpg","20230620100659000000349.jpg","20230623065452000000316.jpg","20230623065500000000967.jpg"};
        String[] type = {"家长","家长","家长","老师","学生","老师"};
        for(int i =0;i < nameList.length;i++){
            values = new ContentValues();
            values.put("username",nameList[i]);
            values.put("avatar",avatarList[i]);
            values.put("circleImagesList",circleImages[i]);
            values.put("circleMsg",messList[i]);
            values.put("likeNum",likeNumList[i]);
            values.put("circleComment",commentList[i]);
            db.insert("circle",null,values);
        }

        for(int i =0;i < nameList.length;i++){
            values = new ContentValues();
            values.put("username",nameList[i]);
            values.put("phone",phoneList[i]);
            values.put("password",passwordList[i]);
            values.put("avatar",avatarList[i]);
            values.put("cover",cover[i]);
            values.put("type",type[i]);
            db.insert("user",null,values);

        }

        db.close();
    }
}